<?php 
class Loggable extends Doctrine_Template
{
    /**
     * Array of Timestampable options
     *
     * @var string
     */
    protected $_options = array('created_by' =>  array('name'          =>  'created_by_user_id',
                                                    'alias'         =>  null,
                                                    'type'          =>  'integer',                                                    
                                                    'disabled'      =>  false,
                                                    'expression'    =>  false,
                                                    'options'       =>  array('notnull' => false)),
                                'updated_by' =>  array('name'          =>  'updated_by_user_id',
                                                    'alias'         =>  null,
                                                    'type'          =>  'integer',                                                    
                                                    'disabled'      =>  false,
                                                    'options'       =>  array('notnull' => false)));

    /**
     * Set table definition for Timestampable behavior
     *
     * @return void
     */
    public function setTableDefinition()
    {
        if ( ! $this->_options['created_by']['disabled']) {
            $name = $this->_options['created_by']['name'];
            if ($this->_options['created_by']['alias']) {
                $name .= ' as ' . $this->_options['created_by']['alias'];
            }
            $this->hasColumn($name, $this->_options['created_by']['type'], null, $this->_options['created_by']['options']);
        }

        if ( ! $this->_options['updated_by']['disabled']) {
            $name = $this->_options['updated_by']['name'];
            if ($this->_options['updated_by']['alias']) {
                $name .= ' as ' . $this->_options['updated_by']['alias'];
            }
            $this->hasColumn($name, $this->_options['updated_by']['type'], null, $this->_options['updated_by']['options']);                        
        }

        $this->addListener(new LoggableListener());
    }
    
    public function setUp()
    {
            if ( ! $this->_options['created_by']['disabled']) {
                $this->hasOne('sfGuardUser as Creator', array(                    
                    'local'    => 'created_by_user_id',
                    'foreign' => 'id'));                
            }
            if ( ! $this->_options['updated_by']['disabled']) {
                $this->hasOne('sfGuardUser as LastModifier', array(                        
                        'local'    => 'updated_by_user_id',
                        'foreign' => 'id'));            
            }
    }
}